The Keras functional API

Coding tutorials

1. Multiple inputs and outputs

2. Tensors and Variables

3. Accessing model layers

4. Freezing layers


Multiple inputs and outputs

Load the acute inflammations dataset

The acute inflammations was created by a medical expert as a data set to test the expert system, which will perform the presumptive diagnosis of two diseases of the urinary system. You can find out more about the dataset here.

Attribute information:

Inputs:

Outputs:

Load the data

Build the model

Plot the model

Compile the model

Fit the model

Plot the learning curves


Tensors and Variables

Create Variable objects

Use and modify Variable values

Create Tensor objects

Create a constant tensor and print its type as well as its shape:

Useful Tensor operations

Doing maths with Tensors

Randomly sampled constant tensors


Accessing model layers

Load the pre-trained model

In this section, we aim to demonstrate accessing layer attributes within a model.

Let's get started by loading the VGG19 pre-trained model from the keras.applications library, which is a very deep network trained on more than a million images from the ImageNet database. The network is trained to classify images into 1000 object categories.

Build a model to access the layer outputs

Load the 'cool cat' picture

In Zambia’s South Luangwa National Park, a photographer had been watching a pride of lions while they slept off a feast from a buffalo kill. When this female walked away, he anticipated that she might be going for a drink and so he positioned his vehicle on the opposite side of the waterhole. The cool cat picture is one of the highly commended 2018 Image from Wildlife Photographer of the Year.

Visualise network features from the input image


Freezing layers

Build the model

Examine the weight matrix variation over training

Freeze layers at build time

Freeze layers of a pre-built model